from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from meiduo_admin.serializers.images import ImageSerializer, SKUSeriazlier
from meiduo_admin.utils import PageNum
from goods.models import SKUImage, SKU

"""图片表的增删改查"""


class ImageView(ModelViewSet):
    # 指定序列化器
    serializer_class = ImageSerializer
    # 指定查询集
    queryset = SKUImage.objects.all()
    # 指定分页器
    pagination_class = PageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    # 获取sku商品信息
    def simple(self, request):
        # 获取sku所有商品的信息
        data = SKU.objects.all()
        # 调用序列化器
        ser = SKUSeriazlier(data, many=True)
        # 返回序列化后的数据
        return Response(ser.data)









